package java44th.group.controlleradvice;

import java44th.group.bean.admin.vo.BaseRespVo;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.apache.shiro.authz.UnauthorizedException;

/**
 * @projectName: project-second
 * @package: java44th.group.controlleradvice
 * @className: ExceptionControllerAdvice
 * @author: 杨浩祥
 * @description: TODO
 * @date: 2022/10/13 17:55
 * @version: 1.0
 */
@ControllerAdvice
public class ExceptionControllerAdvice {

    @ExceptionHandler(HttpMessageNotReadableException.class)
    @ResponseBody
    public BaseRespVo httpMessageNotReadableExceptionResolve(HttpMessageNotReadableException ex){
        ex.printStackTrace();
        return BaseRespVo.falseParameter402("参数有误");
    }

    @ExceptionHandler(MethodArgumentTypeMismatchException.class)
    @ResponseBody
    public BaseRespVo MethodArgumentTypeMismatchExceptionResolve(MethodArgumentTypeMismatchException e ){
        e.printStackTrace();
        return BaseRespVo.falseParameter402("参数有误");
    }


    @ExceptionHandler(AuthorizationException.class)
    @ResponseBody
    public BaseRespVo AuthorizationExceptionResolve(AuthorizationException e){
        e.printStackTrace();
        return BaseRespVo.unAuthc();
    }

    @ExceptionHandler(IncorrectCredentialsException.class)
    @ResponseBody
    public BaseRespVo IncorrectCredentialsExceptionResolve(IncorrectCredentialsException e){
        e.printStackTrace();
        return BaseRespVo.unAuthc();
    }

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseBody
    public BaseRespVo UnauthorizedExceptionExceptionResolve(UnauthorizedException e){
        e.printStackTrace();
        return BaseRespVo.falseParameter();
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public BaseRespVo AllExceptionArgumentTypeMismatchExceptionResolve(Exception e){
        e.printStackTrace();
        return BaseRespVo.unPerms();
    }


}
